layui.config({
    base : "/dhjdglxt/modules/util/"//自定义加载的模块
}).use(['form','layer','jquery','layedit','laydate','laypage','table','commUtil','element','treetable'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : parent.layer,
        laypage = layui.laypage,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.jquery;
    var table = layui.table;
    var commUtil = layui.commUtil;
    var element = layui.element;
    var treetable = layui.treetable;//很重要
    
    
    form.verify({
        otherReq: function(value,item){
          var $ = layui.$;
          var verifyName=$(item).attr('name')
          , verifyType=$(item).attr('type')
          ,formElem=$(item).parents('.layui-form')//获取当前所在的form元素，如果存在的话
		    ,verifyElem=formElem.find('input[name='+verifyName+']')//获取需要校验的元素
		    ,isTrue= verifyElem.is(':checked')//是否命中校验
		    ,focusElem = verifyElem.next().find('i.layui-icon');//焦点元素
		    if(!isTrue || !value){
		            //定位焦点
		            focusElem.css(verifyType=='radio'?{"color":"#FF5722"}:{"border-color":"#FF5722"});
		            //对非输入框设置焦点
		            focusElem.first().attr("tabIndex","1").css("outline","0").blur(function() {
		                focusElem.css(verifyType=='radio'?{"color":""}:{"border-color":""});
		             }).focus();
		            return '必填项不能为空';
		    }
        }
      });

	$("#alarmY").blur(function(){
		var txday=$("#txday").val();
		if(txday==''||txday==null||typeof(txday)=='undefined'||txday=='-请选择-'){ 
			layer.msg("请选选择提醒天数！", {icon: 1});
			return false;
		}
		if(this.value>=parseInt(txday)){
			layer.msg("黄色提醒天数必须小于提醒天数！", {icon: 1});
			this.value='';
		}
	});
	$("#alarmR").blur(function(){
		var txday=$("#txday").val();
		if(this.value>=parseInt(txday)){
			layer.msg("红色色提醒天数必须小于提醒天数！", {icon: 1});
			this.value='';
		}else if(this.value>=parseInt($("#alarmY").val())){
			layer.msg("红色色提醒天数必须小于黄色色提醒天数！", {icon: 1});
			this.value='';
		}
	});
  //监听提交
	form.on('submit(formSubmit)', function(data){
		layer.load(2); 
		var recId='0';
		if(data.field.recId!=''){
			recId=data.field.recId;
		}
		$.ajax({
		    type: "PUT",
		    url: basePath+'/service/jddtgzsz/jddtgzsz/'+recId,
		    data: data.field,
		    async:true,
		    dataType: "json",
		    success: function(data){
		    	//console.log(data);
		    	layer.closeAll('loading');
		    	//debugger
		    	if(data.code=='0'){
		    		layer.msg("操作成功");
		    		 parent.location.reload();	
				}else if(data.code=='5'){
					console.log(data + "-----------------");
					layer.msg(data.message);
				} else {
					layer.msg("操作失败");
				}
		      }
		});
		return false;
	});
})